import vtkmodules.all as vtk


class StreamTracerActor:
    type = "GRAPHIC_ACTOR"
    created_by = "default"

    def __init__(self, OutputPort):
        seedCenters = [
            [0.0, 2.1, 0.5],
            [0.1, 2.1, 0.5],
            [0.1, 2.7, 0.5],
            [0.08, 2.7, 0.5]
        ]
        center = 3
        if center >= len(seedCenters):
            center = len(seedCenters) - 1
        seeds = vtk.vtkPointSource()
        seeds.SetRadius(0.075)
        seeds.SetCenter(seedCenters[center])
        seeds.SetNumberOfPoints(25)
        streamers = vtk.vtkStreamTracer()
        streamers.SetInputData(OutputPort)
        # 流线积分方向
        streamers.SetIntegrationDirectionToBoth()
        # 流线积分类型
        streamers.SetIntegratorTypeToRungeKutta45()
        streamers.SetSourceConnection(seeds.GetOutputPort())
        streamers.SetMaximumPropagation(500)
        streamers.SetMinimumIntegrationStep(0.1)
        streamers.SetMaximumIntegrationStep(1.0)
        streamers.SetInitialIntegrationStep(0.2)
        streamers.Update()
        mapStreamers = vtk.vtkPolyDataMapper()
        mapStreamers.SetInputConnection(streamers.GetOutputPort())
        mapStreamers.SetScalarRange(OutputPort.GetPointData().GetScalars().GetRange())
        streamersActor = vtk.vtkActor()
        streamersActor.SetMapper(mapStreamers)
        self.instance = streamersActor
